<?php

class Admin_Model_Newscat extends Zend_Db_Table_Abstract
{
    protected $_name = 'newscat';
    
    public function getAllData(){
		$query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('c'=>$this->_name),array('c.catId','c.catName','c.catCode','c.shortName','c.display','c.ord'));
        return $this->fetchAll($query);
    }
    public function getDataByCatId($data){
        $query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('c'=>$this->_name),array('c.catId','c.catName','c.catCode','c.shortName','c.display','c.ord'))
                        ->where('catId = ?',(int)$data);
        return $this->fetchRow($query);
    }
    public function getDataCheckUnique($data){
        $query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('c'=>$this->_name),array('c.catId','c.catName','c.catCode','c.shortName','c.display','c.ord'));
        if(isset($data['catName']) && $data['catName']){
            $query->where('catName = ?',$data['catName']);
        }                                
        if(isset($data['catCode']) && $data['catCode']){
            $query->where('catCode = ?',$data['catCode']);
        }                        
        return $this->fetchRow($query);
    }          
    public function addData($data){        
        $data = array('catCode' => $data['catCode'],
                'catName'       => $data['catName'],
                'shortName'     => $data['shortName'],
                'display'       => $data['display'],
                'ord'           => $data['ord']);                
        $idAdd = $this->insert($data);        
        return $idAdd;
    }
    public function updateData($catId = '',$data){        
        $data = array('catCode' => $data['catCode'],
                'catName'       => $data['catName'],
                'shortName'     => $data['shortName'],
                'display'       => $data['display'],
                'ord'           => $data['ord']);
        return $this->update($data, 'catId = '.(int)$catId);
    }            
    public function deleteData($catId){        
        $this->delete('catId = '.(int)$catId);
    }               
}